#pragma once
#include <assert.h>
#include <iostream>

using namespace std;


template <class T>
class Stack
{
public:
	Stack(int n = 4)
	{
		_arr = new T[n];
		_top = 0;
		_capacity = n;
	}

	void Push(const T& x);
	void Pop()
	{
			assert(_top > 0);
			_top--;
	}
	T& Top()
	{
		assert(_top > 0);
		return _arr[_top - 1];
	}
	int Empty()
	{
		return _top == 0;
	}

	~Stack()
	{
		delete[] _arr;
		_top = _capacity = 0;
	}
private:
	T* _arr;
	int _top;
	int _capacity;
};

template <class T>
void Stack<T>::Push(const T& x)
{
	if (_top == _capacity)
	{
		int newcapacity = _capacity * 2;
		T* tmp = new T[newcapacity];

		memcpy(tmp, _arr, sizeof(T) * _top);
		delete[] _arr;

		_arr = tmp;
		_capacity = newcapacity;
	}
	_arr[_top++] = x;
}

//template <typename T>
//void Stack<T>::Pop()
//{
//	assert(_top > 0);
//	_top--;
//}



